package com.test;

import com.itheima.pojo.Customer;
import com.itheima.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class CustomerTest {
    @Test
    public void findCustomerByNameAndJobsTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Customer customer = new Customer();
        customer.setUsername("jack");
        customer.setJobs("teacher");
        List<Customer> customers = sqlSession.selectList("com.itheima.mapper.CustomerMapper.findCustomerByNameAndJobs",customer);
        for (Customer cust : customers) {
            System.out.println(cust);
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void updateCustomerByTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Customer customer = new Customer();
        customer.setId(3);
        customer.setPhone("13555555555");
        customer.setUsername("jack");
        int rows = sqlSession.update("com.itheima.mapper.CustomerMapper.updateByPrimaryKeySelective",customer);
        if (rows > 0) {
            System.out.println("成功");
        }
        else {
            System.out.println("失败");
        }
        sqlSession.commit();
        sqlSession.close();

    }
    @Test
    public void findByArrayTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Integer[] roleIds = {2,3};
        List<Customer>customers = sqlSession
                .selectList("com.itheima.mapper.CustomerMapper.findByArray",roleIds);
        for (Customer customer:customers){
            System.out.println(customer);
        }
        sqlSession.close();
    }
}
